/*
 * @Author: your name
 * @Date: 2021-02-26 15:19:32
 * @LastEditTime: 2021-02-26 16:39:27
 * @LastEditors: Please set LastEditors
 * @Description: 处理微信下拉黑边
 * @FilePath: \web-app\src\utils\forbidScroll.js
 */

export const forbidScroll = (elem) => {
  let flag = false
  elem.addEventListener('touchstart', (evt) => {
    if (elem.contains(evt.target)) {
      flag = true
    } else {
      flag = false
    }
  }, false)
  elem.addEventListener('touchmove', (evt) => {
    evt.prop = flag
  })
}

const handler = (evt) => {
  if (evt.prop) {
    evt.preventDefault()
  }
}

document.body.removeEventListener('touchmove', handler, { passive: false })
document.body.addEventListener('touchmove', handler, { passive: false })
